package com.health.mapp.impl;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.health.db.model.UserPatient;
import com.health.db.service.user.IPatientShortInfoService;
import com.health.mapp.bean.DeletePatientReq;
import com.health.mapp.bean.DeletePatientResp;
import com.health.mapp.bean.Header;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 * 删除userId
 * @author yuchong
 */
public class DeletePatientImpl implements ActionInterface{

	@Autowired
	IPatientShortInfoService patientShortInfoService;
	
    
    private static Logger logger = Logger.getLogger(DeletePatientImpl.class);

    @Override
    public Response execute(Header header, Object reqBean) throws Exception {


    	DeletePatientReq req = (DeletePatientReq) reqBean;
    	DeletePatientResp _resp = new DeletePatientResp();

        if (StringUtils.isEmpty(req.getUserId())||StringUtils.isEmpty(req.getPatientId()))
        {
            _resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
            _resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);

            return _resp;
        }

        try {
				
        	
        UserPatient userPatient = new UserPatient();
        userPatient.setUserId(Long.valueOf(req.getUserId()));
        userPatient.setStatus(1);
        userPatient.setPatientId(Long.valueOf(req.getPatientId()));
        
        patientShortInfoService.updateUserPatientByUserIdPatientId(userPatient);
        	
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
    	

        }catch (Exception e)
        {
            logger.error(e.getMessage());
            _resp.setErrorCode(-1);
            _resp.setErrorMsg("code error");
            logger.info("code error");
        }

        return _resp;
    }


}
